package GameScheduler
{
	import BasicEngine.*;
	import DataStore.DataSource;
	import DataStore.ResourceManager;
	import flash.display.DisplayObject;
	import Map.MapManager;
	import Props.PropManager;
	import SceneUnit.SceneManager;	
	import MenuUnit.MenuManager;	
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	//游戏的整体类
	public class Game
	{
		public var MainCanvas:Sprite;
		public  var MainTimer:Timer;			
		public var Pause:Boolean;
		public  var Width:int;
		public  var  Height:int;		
		private  var tick:int;		
		
		public function Game()
		{
			tick = ClockUnit.Dida * 10;			
			Pause = true;
		}
		
		//初始化
		public function Init(_main:Sprite,_tileWidth:int,_tileHeight:int,_w:int,_h:int,_stage:DisplayObject):void
		{
			Dispatcher.Init();
			EntityManager.Init();
			LoaderManager.Init();
			MsgManager.Init();
			DataSource.Init();
			KeyMouseManager.Init();
			
			MapManager.Init(_tileWidth, _tileHeight);
			PropManager.Init();
			MenuManager.Init(_main, _w, _h);	
			SceneManager.Init(_main,_stage);	
			ResourceManager.Init();
			
			MainTimer = new Timer(tick,0);
			MainTimer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent) :void
			{
				Update();
			});		
		}
		
		public function Update():void
		{
			if (!Pause)
			{
				Dispatcher.ExecuteUpdate();
			}
		}
		
		//添加游戏场景
		public function  AddScene():void
		{
			
		}
		
		//游戏启动，启动游戏调度
		public function Star():void
		{
			MainTimer.start();
			Pause = false;
		}
	}
}